package com.qianyucc.blog.model.vo;

import cn.hutool.core.bean.*;
import com.qianyucc.blog.model.entity.*;
import com.qianyucc.blog.model.enums.*;
import com.qianyucc.blog.utils.*;
import lombok.*;

import java.util.*;

import static com.qianyucc.blog.global.Constants.DEFAULT_DATE_TIME_PATTERN;

/**
 * @author lijing
 * @date 2019-10-13 11:18
 * @description 封装向前端返回的评论信息
 */
@Data
public class CommentVO {
    public static CommentVO create(CommentDO commentDO,UserDO userDO){
        CommentVO commentVO = new CommentVO();
        BeanUtil.copyProperties(commentDO, commentVO);
        if (userDO != null) {
            commentVO.setCommentatorAvatarUrl(userDO.getAvatarUrl());
            commentVO.setCommentatorName(userDO.getName());
        } else {
            // 匿名用户
            commentVO.setCommentatorAvatarUrl(UserType.ANONYMOUS.getAvatar());
            commentVO.setCommentatorName(UserType.ANONYMOUS.getName());
        }
        commentVO.setGmtCreate(Utils.formatDate(commentDO.getGmtCreate(), DEFAULT_DATE_TIME_PATTERN));
        commentVO.setGmtUpdate(Utils.formatDate(commentDO.getGmtUpdate(), DEFAULT_DATE_TIME_PATTERN));
        return commentVO;
    }

    private Long id;
    private String articleId;
    private Long parentId;
    private Integer type;
    private String commentator;
    private String content;
    private String gmtCreate;
    private String gmtUpdate;
    private Long likes;
    private Long comments;

    private String commentatorAvatarUrl;
    private String commentatorName;
    private List<CommentVO> secondLevelComments;
}
